<% /* $Id: problem.jsp 132 2011-08-26 10:23:42Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="header.jsp" %>

<%
	if (user == null)
	{
		response.sendRedirect(Linker.link("login.jsp?return=" + URLEncoder.encode(request.getRequestURI(), AbstractDataServlet.defaultEncoding)));
		return;
	}
	String problemId = request.getParameter("problem_id");
	ContestProblemEntry contestProblemEntry = ContestProblemsModel.getEntry(Long.parseLong(problemId));
	if (null == contestProblemEntry)
	{
		response.sendRedirect(Linker.link("contests/home.jsp?contest_id=" + contest.getId()));
		return;
	}
	ProblemEntry problem = ProblemsModel.getEntry(contestProblemEntry.getProblemId());
	if (contest.getStartTime().after(new Date()) && !user.isAdmin())
	{
%>
		<h2 align="center">Умова задачі буде доступною після початку змагань</h2>	
<%
	}
	else if (null == problem)
	{
%>
		<h2>Задачу не знайдено</h2>
<%
	}
	else
	{
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("problemId", problem.getId());
		List<ProblemStatementEntry> statements = ProblemStatementsModel.getEntries(params);
		
		LocaleEntry requestedLocale = LocalizationModel.getUserLocale(user, request);
		ProblemStatementEntry statementEntry = null;
	%>
		
		<ul>
	<%
		for (ProblemStatementEntry statement : statements)
		{
			LocaleEntry locale = LocalesModel.getEntry(statement.getLocaleId());
			if (locale.getJavaLocale().equalsIgnoreCase(requestedLocale.getJavaLocale()) || statementEntry == null)
				statementEntry = statement;
	%>
			<li>
				<a href="<%= request.getRequestURL() + "?contest_id=" + contest.getId() + "&problem_id=" + contestProblemEntry.getId() + "&locale=" + locale.getJavaLocale() %>">
					<%= locale.getSid() %>
				</a>
			</li>
	<%
		}
	%>
		</ul>	
				
		<h1 align="center">
			<%= bundle.getString("W_PROBLEM") %> <%= problem.getSid() %>: <%= problem.getName() %>
		</h1>
		<div class="content">
			<%= statementEntry != null ? statementEntry.getStatement() : bundle.getString("W_PAGE_NOT_FOUND") %>
		</div>
<%		
	}
%>


<%@ include file="footer.jsp" %>
